package com.fulihui.wgj.admin.api.retention;

import com.fulihui.common.builder.web.JsonResultBuilder;
import com.fulihui.common.result.web.Result;
import com.fulihui.wgj.admin.api.base.BaseController;
import com.fulihui.wgj.admin.api.retention.request.RetentionQueryReq;
import com.fulihui.wgj.admin.api.retention.vo.RetentionVO;
import com.fulihui.wgj.admin.integration.RetentionClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Objects;

/**
 * @author: JY
 * @date: 2018/7/4 11:04
 * 七日留存率
 */
@RestController
@RequestMapping("/retention")
@Api(tags = "七日留存接口")
public class RetentionController extends BaseController {

    @Autowired
    RetentionClient retentionServiceClient;

    @PostMapping("/list")
    @ApiOperation("获取公众号七日留存数据")
    public Result querySevenRetention(@RequestBody @Valid RetentionQueryReq queryReq, BindingResult validResult, HttpServletRequest request) {

        //验证
        Result valid = valid(validResult);
        if (Objects.nonNull(valid)) {
            return valid;
        }

        //设置参数
        queryReq.setAppId(getAppid(request));

        List<RetentionVO> renList = retentionServiceClient.queryWxSevenRetentions(queryReq);

        return JsonResultBuilder.succ(renList);
    }

}
